from __future__ import annotations

from datetime import datetime, timezone
from typing import Any


class APIResponse(dict):
  """Dict subclass providing a compat `model_dump` used in tests/Pydantic contexts."""

  def model_dump(self, *_args, **_kwargs):  # pragma: no cover - helper for external expectations
    return dict(self)


def success_response(data: Any = None, code: int = 0, message: str | None = None) -> APIResponse:
  payload: dict[str, Any] = {
    "code": code,
    "data": data,
    "ts": datetime.now(tz=timezone.utc).isoformat(),
  }
  if message is not None:
    payload["message"] = message
  return APIResponse(payload)
